//
//  YSAccountCenterBottomBar.m
//  Yueshi
//
//  Created by Northwan on 15/7/30.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSAccountCenterBottomBar.h"

@interface YSAccountCenterBottomBar()
@end

@implementation YSAccountCenterBottomBar

+(instancetype)bottomBar{
    return [[[NSBundle mainBundle]loadNibNamed:@"YSAccountCenterBottomBar" owner:nil options:nil]lastObject];
}

-(void)setPrice:(float)price amount:(float)amount{
    if(price==0){
        [self.priceLabel setText:@"¥0.0"];
    }
    else{
        if(amount > 0){
             NSString *priceString =  [NSString stringWithFormat:@"¥%.1f",price-amount];
            NSString *amountString = [NSString stringWithFormat:@" (已优惠¥%.1f元)",amount];
            NSString *formatTimeStr =  [NSString stringWithFormat:@"%@%@",priceString,amountString];
            NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:formatTimeStr];
            [str addAttribute:NSForegroundColorAttributeName value:HEXColor(@"#9e9e9e") range:NSMakeRange(priceString.length,amountString.length)];
            [self.priceLabel setAttributedText:str];
        }else{
             NSString *priceString =  [NSString stringWithFormat:@"¥%.1f",price];
            [self.priceLabel setText:priceString];
        }
    }
}

- (IBAction)tapAccount:(id)sender {
    if(self.operation){
        self.operation();
    }
}

@end
